package com.zhenmyan.secdeal.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * description:
 *
 * rabbitmq都是现将消息发送给交换机，然后转发到队列中
 * 而转发有不同的方式，这里是direct模式
 *
 * 配置类：需要设置队列和交换机名称，然后将队列与路由key进行绑定
 *
 * @author 颜真明
 * @date 2023/5/15  9:39
 */
@Configuration
public class RabbitMQDirectConfig {

    private static final String DIRECT_QUEUE_1= "direct_queue_1";

    private static final String DIRECT_QUEUE_2 = "direct_queue_2";

    private static final String DIRECT_EXCHANGE = "direct_exchange";

    private static final String ROUTING_KEY_1 = "routing_key_1";

    private static final String ROUTING_KEY_2 = "routing_key_2";


    @Bean
    public Queue directQueue1(){
        return new Queue(DIRECT_QUEUE_1);
    }
    @Bean
    public Queue directQueue2(){
        return new Queue(DIRECT_QUEUE_2);
    }

    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(DIRECT_EXCHANGE);
    }

    /**
     * 将队列1绑定到路由key1
     *
     * @return
     */
    @Bean
    public Binding directBinding1() {
        return BindingBuilder.bind(directQueue1()).to(directExchange()).with(ROUTING_KEY_1);
    }

    /**
     * 将队列2绑定到路由key2
     *
     * @return
     */
    @Bean
    public Binding directBinding2() {
        return BindingBuilder.bind(directQueue2()).to(directExchange()).with(ROUTING_KEY_2);
    }


}
